package cn.message.web;

import cn.itcast.pojo.packageOrder;
import cn.itcast.util.OutputStringController;
import cn.message.service.IPackageOrderService;
import javafx.beans.binding.ObjectExpression;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 郭智超
 * @create 2020-05-27 11:04
 */
@Slf4j
@RestController
@RequestMapping(value = "/dhn/message",produces = "text/html;charset=UTF-8")
public class PackageOrderController {

    @Resource
    private OutputStringController osc;

    @Resource
    private IPackageOrderService packageOrderService;

    @ResponseBody
    @RequestMapping("/getAllPackageOrder")
    public String getAllPackageOrder(@RequestBody Map<String,String> map) {
        String results = "";
        Map<String, Object> resultMap = packageOrderService.getAllPackageOrder(map);
        //获取符合查询条件的总记录条数
        int count = (int)resultMap.get("count");
        //获取所有打包订单信息
        Object packageOrderList = resultMap.get("packageOrderList");

        if(packageOrderList == null){
            results = osc.resultFailure("no", "");
            log.debug("查询所有打包订单信息失败");
        }
        else {
            results = osc.resultSuccess("yes",packageOrderList, count);
            log.debug("查询所有打包订单信息成功");
        }
        return results;
    }

    @ResponseBody
    @RequestMapping("/getPackageOrderItem")
    public String getPackageOrderItem(@RequestBody Map<String,String> map){
        String results = "";
        Map<String, Object> resultMap = packageOrderService.getAllPackageOrderItem(map);
        //获取符合查询条件的总记录条数
        int count = (int)resultMap.get("count");
        //获取所有打包订单明细信息
        Object packageOrderItemList = resultMap.get("packageOrderItemList");

        if(packageOrderItemList == null){
            results = osc.resultFailure("no", "");
            log.debug("查询打包订单明细信息失败");
        }
        else {
            results = osc.resultSuccess("yes",packageOrderItemList, count);
            log.debug("查询打包订单明细信息成功");
        }
        return results;
    }

    @ResponseBody
    @RequestMapping("/exportPackageOrder")
    public String exportPackageOrder(@RequestBody Map<String,String> map){
        String results = "";
        List<packageOrder> packageOrderList = packageOrderService.exprotPackageOrder(map);
        if(packageOrderList.isEmpty()){
            return osc.failure("订单导出失败");
        }else {
            results = osc.resultSuccess("获取所有打包订单成功",packageOrderList);
        }
        return results;
    }

}
